//
// Created by tunm on 2024/3/14.
//

#include "simple_semantic.h"
#include "predictor.h"
#include "serror.h"
#include "log.h"
#include "version.h"

namespace solex {

RetCode SOLEX_API InitSimpleSemantic(const Configuration& config) {
    static std::atomic<bool> isInitialized(false);

    if (isInitialized) {
        LOGW("Repeated initialization is not supported!");
        return SERR_ALREADY_INITIALIZED;
    }

    auto ret = PROCESS->Initialization(config);
    if (ret == SSUCCEED) {
        isInitialized = true;
    }

    return ret;
}

RetCode SOLEX_API AnalysisOfSentence(const Sentence& sentence, AnalysisResult& result) {
    auto ret = PROCESS->AnalyseSentence(sentence, result);

    return ret;
}

RetCode SOLEX_API QueryVersion(Version& version) {
    version.major = std::stoi(SIMPLE_SEMANTIC_VERSION_MAJOR_STR);
    version.minor = std::stoi(SIMPLE_SEMANTIC_VERSION_MINOR_STR);
    version.patch = std::stoi(SIMPLE_SEMANTIC_VERSION_PATCH_STR);

    return SSUCCEED;
}

}   // namespace solex